package com.lqh.controller;

import com.lqh.annotation.LogFlag;
import com.lqh.pojo.Emp;
import com.lqh.pojo.EmpQueryParam;
import com.lqh.pojo.PageResult;
import com.lqh.pojo.Result;
import com.lqh.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/emps")
@RestController
public class EmpController {
    @Autowired
    private EmpService empService;

    @GetMapping
    public Result pageSelect(EmpQueryParam empQueryParam) {
        log.info("分页展示：{}",empQueryParam);
        PageResult<Emp> pageResult = empService.pageSelect(empQueryParam);
        return Result.success(pageResult);
    }
    @LogFlag
    @PostMapping
    public Result save(@RequestBody Emp emp) {
        log.info("新增员工信息：{}",emp);
        empService.save(emp);
        return Result.success();
    }

    @LogFlag
    @DeleteMapping
    public Result delete (@RequestParam List<Integer> ids){
        log.info("要删除id为{}的员工",ids);
        empService.deleteByIds(ids);
        empService.deleteByEmpIds(ids);
        return Result.success();
   }
   @GetMapping("/{id}")
   public Result getInfo(@PathVariable Integer id){
        log.info("查询回显id为{}的数据",id);
        Emp emp = empService.getInfo(id);
        return Result.success(emp);
   }
   @LogFlag
   @PutMapping
   public Result update(@RequestBody Emp emp){
        log.info("修改员工信息：{}",emp);
        empService.update(emp);
        return Result.success();
    }
}
